# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=gplugin
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.27.0
pkgrel=1
arch=('any')
pkgdesc="A GObject based library that implements a reusable plugin system (mingw-w64)"
license=("LGPL 2")
url="https://bitbucket.org/gplugin/main"
depends=("${MINGW_PACKAGE_PREFIX}-gtk3")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "gettext")
options=('strip' '!debug' 'staticlibs')
source=("${_realname}-${pkgver}.tar.bz2"::https://bitbucket.org/${_realname}/main/downloads/${_realname}-${pkgver}.tar.bz2
        001-win.patch)
sha256sums=('e9ea776497978097bd1ffcfa49521b8cddb333a37a46c3c14220337d2a32f081'
            '935f24bebbeaf323283b6b506c9a81a124a9ac47f03ac01c9380ca499f7082b0')

prepare() {
  cd "$srcdir"/${_realname}-${pkgver}

  patch -p1 -i ${srcdir}/001-win.patch
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G "MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_SKIP_RPATH=ON \
    -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
    -DCMAKE_C_FLAGS="${CFLAGS}" \
    -DBUILD_GJS=OFF \
    -DBUILD_LUA=OFF \
    -DBUILD_PYTHON=OFF \
    -DBUILD_SEED=OFF \
    -DTESTING_ENABLED=OFF \
    -DBUILD_GIR=ON \
    -DBUILD_HELP2MAN=OFF \
   ../${_realname}-${pkgver}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install

  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}
  cp ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING

  mv "${pkgdir}${MINGW_PREFIX}"/lib/libgplugin.dll "${pkgdir}${MINGW_PREFIX}"/bin/
  mv "${pkgdir}${MINGW_PREFIX}"/lib/libgplugin-gtk.dll "${pkgdir}${MINGW_PREFIX}"/bin/
}
